package fr.mma.scrumm.dao;

import java.util.Collection;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class Dao<METIER> {
	
	private Class<METIER> classe;
	
	public Dao(Class<METIER> pClasse) {
		this.classe = pClasse;
	}

	public METIER getByKey(Object key) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		return pm.getObjectById(classe, key);
	}

	public void save(METIER sprint) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		pm.makePersistent(sprint);
		pm.close();
	}

	@SuppressWarnings("unchecked")
	public Collection<METIER> getAll() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(classe);
		return (List<METIER>) query.execute();
	}
}
